package fhq.hcmute.edu.vn.activities;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.Handler;

/**
 * @author Hien Nguyen Oct 4, 2012
 */
public class WifiStateChangedReceiver extends BroadcastReceiver {

	public static final int WIFI_ON = 1;
	public static final int WIFI_OFF = -1;
	public static final int WIFI_UNKNOWN = 0;
	private Handler handler;

	public WifiStateChangedReceiver(Handler handler) {
		this.handler = handler;
	}

	@Override
	public final void onReceive(Context context, Intent intent) {
		int extraWifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
				WifiManager.WIFI_STATE_UNKNOWN);
		switch (extraWifiState) {
		case WifiManager.WIFI_STATE_DISABLED:
			handler.sendEmptyMessage(WIFI_OFF);
			break;
		case WifiManager.WIFI_STATE_ENABLED:
			handler.sendEmptyMessage(WIFI_ON);
			break;
		case WifiManager.WIFI_STATE_ENABLING:
			break;
		case WifiManager.WIFI_STATE_UNKNOWN:
			handler.sendEmptyMessage(WIFI_UNKNOWN);
			break;
		default:
			break;
		}
	}
}
